package org.example.composition;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author Stranger
 * @version 1.0
 * @description: TODO
 * @date 2022/11/6 20:06
 */
public class FileFolder {

    private String name;

    private List<FileFolder> fileFolders;

    public void addSub(FileFolder fileFolder) {
        fileFolders.add(fileFolder);
    }

    public FileFolder(String name) {
        this.name = name;
        this.fileFolders = new ArrayList<FileFolder>();
    }

    public FileFolder(String name, FileFolder... fileFolders) {
        this.name = name;
        this.fileFolders = new ArrayList<FileFolder>(Arrays.asList(fileFolders));
    }

    public boolean hasSub() {
        return !this.fileFolders.isEmpty();
    }

    public String getName() {
        return name;
    }

    public void print() {
        this.printf(this, "");
    }

    private void printf(FileFolder fileFolder, String prefix) {
        System.out.println(prefix + fileFolder.getName());
        prefix += " ";
        for (FileFolder folder : fileFolder.fileFolders) {
            printf(folder, prefix);
        }
    }
}
